function throttle(fn, gapTime) {
  if (gapTime == null || gapTime == undefined) {
    gapTime = 1500
  }
  let _lastTime = null
  // 返回新的函数
  return function () {
    let _nowTime = + new Date()
    if (_nowTime - _lastTime > gapTime || !_lastTime) {
      fn.apply(this, arguments)   //将this和参数传给原函数
      _lastTime = _nowTime
    }
  }
}

function time() {
  var date = new Date();
  var year = date.getFullYear(); //获取当前年份   
  var mon = date.getMonth() + 1; //获取当前月份   
  var da = date.getDate(); //获取当前日   
  var day = date.getDay(); //获取当前星期几   
  var h = date.getHours(); //获取小时   
  var m = date.getMinutes(); //获取分钟   
  var s = date.getSeconds(); //获取秒   
  if (mon >= 1 && mon <= 9) {
    mon = "0" + mon;
  }
  if (da >= 0 && da <= 9) {
    da = "0" + da;
  }
  if (h >= 0 && h <= 9) {
    h = "0" + h;
  }
  if (m >= 0 && m <= 9) {
    m = "0" + m;
  }
  if (s >= 0 && s <= 9) {
    s = "0" + s;
  }
  return year + '-' + mon + '-' + da + ' ' + h + ':' + m + ':' + s;
}

module.exports = { throttle, time }